import { renderElectronApiInvoke, renderElectronApiSend } from "./render";

const { app, BrowserWindow, Menu, ipcMain } = require("electron");
const path = require("node:path");

let win;

const createWindow = () => {
  win = new BrowserWindow({
    width: 1500,
    height: 1000,
    webPreferences: {
      sandbox: false,
      contextIsolation: true,
      nodeIntegration: true,
      preload: path.join(__dirname, "../preload/index.js"),
    },
  });
  win.removeMenu();
  // win.loadFile("src/renderer/index.html");
  win.loadURL("http://localhost:5173");
};

app.whenReady().then(() => {
  createWindow();
  win.webContents.openDevTools();

  for (const iterator in renderElectronApiSend) {
    ipcMain.on(iterator, renderElectronApiSend[iterator]);
  }
  for (const iterator in renderElectronApiInvoke) {
    ipcMain.handle(iterator, renderElectronApiInvoke[iterator]);
  }
});
